angular.module('Controller')
.controller('QgyConfigureTypeModalCtrl',($scope,urls,$localStorage,NgTableParams,commonUtil,cryptUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.type=type=items.type
    $scope.data=data=items.data
    $scope.modalTitle=if type=='new' then '新建房间标配' else '编辑房间标配'
    newData=()->
        reqData={
            "apartmentId":$scope.data.apartmentId
            "type":0
            "name":$scope.data.name
            "description":$scope.data.description
        }
        if $scope.data.providerTime
            reqData.providerTime=moment($scope.data.providerTime).format('YYYY-MM-DD HH:mm:ss')
        $http.post("/configureType",reqData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo($scope.modalTitle+'成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError(resp.message)
        )
    editData=()->
        reqData={
            "name":$scope.data.name
            "description":$scope.data.description
        }
        $http.put("/configureType/#{data.id}",reqData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo($scope.modalTitle+'成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError(resp.message)
        )
    $scope.confirm = ()->
        if type=='new'
            newData()
        else
            editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')
)